import Hilo from "./../public/js/hilo-standalone.js"

interface Parameter{
    el :object,
    images :Array< {id:string, src:string} >,
    body():void
}

var Anim = function Anim(Parameter) {
    this.el = Parameter.el;
    this.images = Parameter.images;
    this.body = Parameter.body;

    this.init()
};

Anim.prototype = {
    _width: window.innerWidth * 2,
    _height: window.innerHeight * 2,
    rem(value) {
        return value / 10 * (this._width / 64);
    },
    rh(value) {
        return value * (this._height / 1009);
    },
    ticker: new Hilo.Ticker(50),
    queue: new Hilo.LoadQueue(),
    init() :any{// 初始化
        if (!this.el){
            return;
        }
        this.lodingAnim(40);
        this.structure();
        var _self = this;
    },
    structure() {// 开始基础设置
        this.stage = new Hilo.Stage({ // 初始化舞台
            renderType: "canvas",
            container: this.el,
            width: window.innerWidth * 2,
            height: window.innerHeight * 2,
            scaleX: 0.5,
            scaleY: 0.5
        })

        var _self = this;
        this.ticker.addTick(this.stage); // FPS
        this.ticker.start();
        this.ticker.addTick(Hilo.Tween);

        this.queue.add(this.images); // 图片载入
        this.queue.start();

        this.stage.enableDOMEvent([Hilo.event.POINTER_START, Hilo.event.POINTER_MOVE, Hilo.event.POINTER_END]); // 开启事件     
        if (this.images.length === 0) {
            _self.start();
        }
        _self.queue.on("complete", function () {// 图片载入完成 执行主代码
            _self.start();
        });
    },
    start() {// 主代码
        this.body();
    },
    reset() {// 停止所有动画并删除所有元素
        console.log("重置");
        Hilo.Tween.removeAll();
        this.stage.removeAllChildren();
    },
    _error(message, callback) {// 报错弹框
    },
    lodingAnim(num) {// 加载动画
    },
    endReset() {// 断链后重置
    }
};


export default Anim;